package com.mes.handler;

import org.codehaus.jettison.json.JSONObject;
import org.openbravo.client.kernel.BaseActionHandler;
import org.openbravo.dal.service.OBDal;

import java.util.Map;

//物料管理查看物料是否关联产品图纸
public class CheckProductHandler extends BaseActionHandler {
	@Override
	protected JSONObject execute(Map<String, Object> parameters, String data) {
		JSONObject jsonRep = new JSONObject();
		try {
			jsonRep.put("flag", true);
			JSONObject jsonData = new JSONObject(data);
			String productId = jsonData.getString("productId");


			String sql = "select a.drawing_path  from m_product a where a.m_product_id = '" + productId + "'";


			String oql = "select a.drawing_name  from m_product a where a.m_product_id = '" + productId + "'";

			String result = (String) OBDal.getInstance().getSession().createSQLQuery(sql).uniqueResult();
			String results = (String) OBDal.getInstance().getSession().createSQLQuery(oql).uniqueResult();
			if (result == null) {
				jsonRep.put("message", "该物料没有上传图片！！");
				jsonRep.put("flag", false);
			} else {
				jsonRep.put("meg", result);
				jsonRep.put("names", results);
				jsonRep.put("flag", true);
			}
			OBDal.getInstance().commitAndClose();
		} catch (Exception e) {
			OBDal.getInstance().rollbackAndClose();
			e.printStackTrace();
		}
		return jsonRep;
	}
}
